const app = getApp()

Page({
   data: {
      position: app.globalData.config.schoolPosition,
      polyline: [],
      circles: [{
         ...app.globalData.config.schoolPosition,
         radius: 1000,
         color: "#ff0000",
         fillColor: "#00000010",
         strokeWidth: 2,
      }],
      controls: [
         {
            id: 1,
            position: {
               left: 20,
               top: wx.getSystemInfoSync().windowHeight - 70,
               width: 40,
               height: 40,
            },
            iconPath: '/assets/images/location.png',
            clickable: true,
         },
         {
            id: 2,
            position: {
               left: 20,
               top: wx.getSystemInfoSync().windowHeight - 120,
               width: 40,
               height: 40,
            },
            iconPath: '/assets/images/school.png',
            clickable: true,
         },
      ]
   },
   handleControlTap({ controlId }) {
      if (controlId === 1) {
         // 定位
         // 获取当前位置
         wx.getLocation({
            type: 'gcj02',
            success: ({ latitude, longitude }) => { 
               // 设置地图中心坐标     
               this.setData({
                  position: {
                     latitude, longitude
                  },
                  polyline: [{
                     points: [
                        { latitude, longitude }, // 自己的位置
                        { ...app.globalData.config.schoolPosition, } // 学校的位置
                     ],
                     color:"#FF0000DD",
                     width: 2,
                     dottedLine: true
                  }]
               })    
            }
         })
      } else if (controlId === 2) {
         // 回去学校
         this.setData({
            position: app.globalData.config.schoolPosition,
         }) 
      }
   }
})